from apps.system.learn.baseViews import *
from django.core.exceptions import ValidationError

def validationFun():
    raise ValidationError('articleId参数必填')


class LearnForPViewSet(BaseLearnViewSet):
    authentication_classes = []
    permission_classes = []
    def get_queryset(self):
        _list = LearnDao().findAll()
        return _list

class LearnViewSet(BaseLearnViewSet):
    
    def get_queryset(self):
        _list = LearnDao().findAll().prefetch_related('users')
        return _list

    @action(methods=['post'], detail=False,authentication_classes=[],permission_classes=[])
    def raiseTest(self, request):
        params = getRequestParams(self.request)
        try:
            validationFun()
        except ValidationError as e:
            return Response(response_message(e.message))

    @action(methods=['post'], detail=False)
    def handle(self, request):
        params = getRequestParams(self.request)

        return Response(response_message('操作成功'))